//
//  CommentCell.m
//  MyBlog
//
//  Created by NCS on 16/12/20.
//  Copyright © 2016年 YSL. All rights reserved.
//

#import "CommentCell.h"

const CGFloat AVATAR_HEIGHT = 48;
const CGFloat CELL_GAP = 48;

@implementation CommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setData:(DetailCellModel *)model {
    self.model = model;
    
    self.avatar.image = [UIImage imageNamed:model.avatar];
    self.name.text = model.name;
    self.time.text = model.time;
    self.device.text = model.device;
    self.likes.text = model.likes;
    self.content.text = model.content;
    
    [self getCellHeight];
    
    
//    self.contentHeightConstraint.constant = self.cellHeight;
//    [self updateConstraints];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)like:(UIButton *)sender {
}

- (IBAction)comment:(UIButton *)sender {
}

- (void)getCellHeight {
    if (self.model == nil) {
        return;
    }
    
    self.cellHeight = [CommentCell getCellHeightByWidth:DScreenWidth Title:self.content.text font:[UIFont systemFontOfSize:17]];
    
    self.model.cellHeight = self.cellHeight;
//    [self updateConstraints];
}

+ (CGFloat)getCellHeightByWidth:(CGFloat)width Title:(NSString *)title font:(UIFont *)font {
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
    label.text = title;
    label.font = font;
    label.numberOfLines = 0;
    [label sizeToFit];
    CGFloat height = label.frame.size.height + AVATAR_HEIGHT + CELL_GAP;
    return height;
}

@end
